<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/5
 * Time: 16:45
 */

namespace Admin\Controller;


use Admin\Common\CommonController;

class RuleController  extends CommonController
{
    //规则列表
    public function lists(){
       //查找所有的规则数据
        $rules=M('authRule')->select();
        $this->assign('rules',$rules);
//        dd($rules);
        $this->display();
    }
    //规则添加，和编辑
   public  function addrules(){
       $id=I('get.id');
       if($id){
         //标识编辑，查出旧数据
         $olddate=M('authRule')->where("id=$id")->find();
       }
       if(IS_POST){
           if($id){
               //标识编辑
               $_GET['id']=$id;
           }
            $res=D('authRule')->addrules(I('post.'));
          $this->jump($res,'lists');
       }
       $this->display();
   }
    //规则删除
    public function delrule(){
        $id=I('get.id');
        $res=M('authRule')->where("id=$id")->delete();
        if($res){
          $this->success('删除成功');die;
        }else{
            $this->error('删除失败');die;
        }
    }
}